package com.myapp.ruyixing.utils;

import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public class KeyboardUtils {
	/**
	 * 切换软键盘显示状态
	 * 
	 * @param context
	 * @param editText
	 * @param visible
	 */
	public static void setKeyboardVisibility(Context context,
			EditText editText, boolean visible) {
		if (context == null || editText == null)
			return;
		InputMethodManager imm = (InputMethodManager) context
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		if (visible) {
			imm.toggleSoftInput(InputMethodManager.RESULT_UNCHANGED_SHOWN,
					InputMethodManager.HIDE_NOT_ALWAYS);
		} else {
			imm.hideSoftInputFromWindow(editText.getWindowToken(),
					InputMethodManager.HIDE_NOT_ALWAYS);
		}
	}
}
